﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DAO;
using DAO_DTO_WS.DTO;

namespace LayoutTemplate
{
    public partial class DoanhNghiep_DangKyBan : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int tinhtrang =0;
            try
            {
                tinhtrang = int.Parse(Session["TinhTrang"].ToString());
            }
            catch
            {
                Response.Redirect("TrangLoi.aspx");
            }
            if (tinhtrang != 2)
                Response.Redirect("TrangChu.aspx");
        }

        protected void btnDangKyBan_Click(object sender, EventArgs e)
        {
            SanPhamDTO sp = new SanPhamDTO();
            int maDoanhNghiep = DoanhNghiepDAO.LayDNTheoTenDangNhap(Session["TenDangNhap"].ToString()).MaDoanhNghiep;
            try
            {
                sp.DiemNoiBat = tbDiemNoiBat.Text.Trim();
                sp.DieuKien = tbDieuKien.Text.Trim();
                sp.GiaTietKiem = long.Parse(tbGiaBan.Text.Trim());
                sp.GiaGoc = long.Parse(tbGiaGoc.Text.Trim());
                sp.SoLuong = int.Parse(tbSoLuong.Text.Trim());
                sp.SoLuongToiThieu = int.Parse(tbSoLuongToiThieu.Text.Trim());
                sp.TieuDe = tbTenSanPham.Text.Trim();
                sp.ThoiGianBatDau = DateTime.Parse(tbThoiGianBatDau.Text.Trim());
                sp.ThoiGianKetThuc = DateTime.Parse(tbThoiGianKetThuc.Text.Trim());
                sp.ThongTin = tbThongTin.Text.Trim();
                sp.MaDiaPhuong = int.Parse(DropDownList1.SelectedValue);
                sp.MaDoanhNghiep = maDoanhNghiep;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            sp.TinhTrang = 0;
            SanPhamDAO.ThemMoi(sp);
            Response.Redirect("ThanhCong.aspx?Success=1");
        }
    }
}
